package com.xgry.bpm.api.base.userInfo.service.impl;

import com.xgry.bpm.api.base.userInfo.entity.UserInfo;
import com.xgry.bpm.api.base.userInfo.mapper.UserInfoMapper;
import com.xgry.bpm.api.base.userInfo.service.UserInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.apache.http.HttpStatus;

import java.util.List;

/**
* <p>
    * UserInfo服务实现类
    * </p>
*
* @author adrian
* @since 2020-07-09
*/
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>implements UserInfoService {

    @Override
    public int deleteById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        return baseMapper.deleteById(id);
    }

    @Override
    public UserInfo selectById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        UserInfo data=baseMapper.selectById(id);
        return data;
    }

    @Override
    public List<UserInfo>selectAll(UserInfo record){
        QueryWrapper<UserInfo>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        List<UserInfo>list=baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public IPage<UserInfo>selectPage(IPage<UserInfo> page , UserInfo record){
        // 查询条件
        QueryWrapper<UserInfo>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public IPage<UserInfo>getPage(IPage<UserInfo>page,QueryWrapper<UserInfo>queryWrapper){
        return baseMapper.selectPage(page,queryWrapper);
    }
    @Override
    public UserInfo findByPersonnelId(int parseInt) {
        List<UserInfo> userInfos = baseMapper.selectList(new QueryWrapper<UserInfo>() {{
            this.eq("personnelId", parseInt);
        }});
        return userInfos.get(0);
    }

    @Override
    public UserInfo getUserInfoByNameAndPassword(String username) {
        return baseMapper.selectList(new QueryWrapper<UserInfo>() {{
            this.eq("userName", username);
        }}).get(0);
    }
}